home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6887 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  114 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Please please help a newbie!!
  5. Date: 15 Feb 1996 23:40:48 GMT
  6. Organization: OpenVision
  7. Message-ID: <4g0ga0$sdm@spanky.pls.ov.com>
  8. References: <4fth5k$43v@pacifica.access.ch>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 43v@pacifica.access.ch, tombeck@usemail.com (Thomas Beck) writes:
  13. >Hi there!
  14. >
  15. >It's quite embarrassing to ask those two questions, because they seem 
  16. >absolutely stupid (they probably are). Yesterday I started to learn C/C++. I 
  17. >bought a 700 pages book with a cd included that has two compilers on it). I 
  18. >fully understand the chapter about the types, but the things I program just 
  19. >can't be compiled. I extracted the following two problems:
  20. >
  21. >----------- example 1: -------------
  22. >int i;
  23. >int & a=i;
  24. >
  25. >main() {
  26. >}
  27. >--------------------------------------------
  28.  
  29. In the above example, '&' is not a data type, it is an operator.
  30. If you want a integer pointer to 'i' you need to do the following:
  31.  
  32. int i, *a;
  33.  
  34. main(){
  35.    a = &i;
  36. }
  37.  
  38. >
  39. >This is not compiled, I get the following output with  Symantec C++ 6.11:
  40. >
  41. >D:\SC>sc test1.c        
  42. >
  43. >sccx test1.c
  44. >int & a=i;
  45. >    ^
  46. >test1.c(2) : Error: '=', ';' or ',' expected
  47. >
  48. >--- errorlevel 1
  49. >
  50. >The second thing that doesn't work is this:
  51. >
  52. >----------- example 2: -------------
  53. >struct abc {
  54. >  int i;
  55. >  char a;
  56. >  void f1() {
  57. >  };
  58. >};
  59. >
  60. >main() {
  61. >}
  62. >---------------------------------------------
  63.  
  64. In the example above, you cannot define a function in the body of a
  65. struct.  If you want a pointer to a function, you need to do the following:
  66.  
  67. struct abc{
  68.    int i;
  69.    char a;
  70.    void (*f1)();  /* This reads as "f1 a pointer to a function returning void" */
  71. };
  72.  
  73. main() {
  74. }
  75.             Fletcher.Glenn@ov.com
  76.  
  77.  
  78. >This isn't compiled either, here's the output:
  79. >
  80. >D:\SC>sc test2.c
  81. >
  82. >sccx test2.c
  83. >  void f1() {
  84. >            ^
  85. >test2.c(4) : Error: illegal type for 'f1' member
  86. >
  87. >--- errorlevel 1
  88. >
  89. >
  90. >Before you think I'm absolutely stupid... I used to be very good at Pascal 
  91. >(TP 6.0), and I'm also experienced in OOP under Pascal. I have no clue of 
  92. >C++, however, and I can only rely on what's written in that book. Apparently 
  93. >it doesn't tell me the truth, does it?
  94. >
  95. >Can you please help me with those two problems (referenced variable and 
  96. >function within a class), so that I can go on and learn a few more difficult 
  97. >things?
  98. >
  99. >Thanks in advance,
  100. >
  101. >Thomas Beck, tombeck@usemail.com
  102. >
  103. >=================================================================
  104. >Summer's day, as she passed away. Birds were singing in the
  105. >summer sky; then came the rain, and once again, a tear fell
  106. >from her mother's eye...
  107. >=================================================================
  108. >
  109.  
  110.  
  111.  
  112.  
  113.  
  114.